package com.csdj.server.controller;


import com.csdj.server.pojo.Position;
import com.csdj.server.pojo.RespBean;
import com.csdj.server.service.IPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZouLi
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/employee/basic/pos")
@Api(tags = "职位管理PositionController")
public class PositionController {

    /**
     * 注入positionService
     **/
    @Autowired
    private IPositionService positionServiceImpl;

    /**
     * @Description: 获取所有职位信息
     * @Param []
     * @Return java.util.List<com.csdj.server.pojo.Position>
     * @Throws
     **/
    @ApiOperation(value = "获取所有职位信息")
    @GetMapping("/getAllPosition")
    public List<Position> getPositionInfo(){
        return positionServiceImpl.list();
    }

    /**
     * @Description: 添加职位信息
     * @Param [position]
     * @Return com.csdj.server.pojo.RespBean
     * @Throws
     **/
    @PostMapping("/savePosition")
    @ApiOperation(value = "添加职位信息")
    public RespBean addPosition(@RequestBody Position position){
        position.setCreateDate(LocalDateTime.now());
        if (positionServiceImpl.save(position)) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    /**
     * @Description: 修改职位信息
     * @Param [position]
     * @Return com.csdj.server.pojo.RespBean
     * @Throws
     **/
    @ApiOperation(value = "修改职位信息")
    @PutMapping("/updatePosition")
    public RespBean updatePosition(@RequestBody Position position){
        if (positionServiceImpl.updateById(position)) {
            return RespBean.success("修改成功！");
        }
        return RespBean.error("修改失败！");
    }

    @ApiOperation(value = "删除职位信息")
    @DeleteMapping("/deletePosition/{id}")
    public RespBean deletePosition(@PathVariable Integer id){
        if (positionServiceImpl.removeById(id)) {
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    @ApiOperation(value = "批量删除职位信息")
    @DeleteMapping("/deletePositionByIds")
    public RespBean deletePositionByIds(Integer[] ids){
        if (positionServiceImpl.removeByIds(Arrays.asList(ids))) {
            return RespBean.success("批量删除成功！");
        }
        return RespBean.error("批量删除失败！");
    }

}
